perf: zero-copy command parsing + keyspace fast path - #107
Merged
Conversation
replaces data.to_vec() + String::from_utf8() with std::str::from_utf8() + to_owned(). validates UTF-8 directly on the Bytes buffer without an intermediate Vec<u8> allocation, then allocates only once for the final String.
adds Keyspace::get_string() that returns Option<Bytes> directly, avoiding the Value enum wrapper. the shard GET dispatch now uses this path — Bytes::clone() is just a refcount increment, and we skip the full Value::clone() + pattern match overhead.
replaces DefaultHasher (SipHash-2-4) with ahash for shard key routing. ahash is ~3x faster for short keys. shard routing is trusted internal logic — the keys come from client commands, not untrusted input that could craft hash collisions.
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
* perf: validate UTF-8 in-place in extract_string replaces data.to_vec() + String::from_utf8() with std::str::from_utf8() + to_owned(). validates UTF-8 directly on the Bytes buffer without an intermediate Vec<u8> allocation, then allocates only once for the final String. * perf: add get_string() for direct Bytes return on GET adds Keyspace::get_string() that returns Option<Bytes> directly, avoiding the Value enum wrapper. the shard GET dispatch now uses this path — Bytes::clone() is just a refcount increment, and we skip the full Value::clone() + pattern match overhead. * perf: use ahash for shard routing instead of SipHash replaces DefaultHasher (SipHash-2-4) with ahash for shard key routing. ahash is ~3x faster for short keys. shard routing is trusted internal logic — the keys come from client commands, not untrusted input that could craft hash collisions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
tier 2 performance optimizations from the throughput/latency audit.
Bytesbuffer withstd::str::from_utf8()instead of copying to aVec<u8>first viato_vec(). saves one allocation per string argument per commandOption<Bytes>directly, avoiding theValueenum clone wrapper. shard GET dispatch now uses this path —Bytes::clone()is just a refcount incrementDefaultHasher(SipHash-2-4) with ahash (~3x faster for short keys). shard routing is trusted internal logic so DoS-resistant hashing is unnecessarywhat was tested
cargo test --workspace --features protobuf— all tests pass (994+ tests)cargo clippy --workspace --features protobuf -- -D warnings— cleandesign considerations
get_string()is additive —get()remains for callers that need the fullValue. the shard dispatch wraps the result back intoValue::String()to keep theShardResponsetype unchanged